/* Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.classdiagram.figures;

import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.PapyrusPlugin;
import com.cea.papyrus.core.figures.ClassifierFigure;
import com.cea.papyrus.core.helper.ModelerHelper;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;


/**
 * Defines the view of a component in a class diagram
 * 
 * @author Agnes Lanusse
 * @since  April 07
 */
public class ComponentFigure extends ClassifierFigure {
	
	
	/**
	 * {@inheritDoc}
	 */
	
	public void refreshPresentation(String presentation, Element selection, GraphElement ge) {
		org.eclipse.swt.graphics.Image icon =PapyrusPlugin.getIconElement(selection);
	
		/* if the presentation is icon or icon with text, we can set the icon */
		if ( (icon != null) 
			&& (presentation.equals(ModelerHelper.ICON_STEREOTYPE_PRESENTATION)
				 || presentation.equals(ModelerHelper.TEXT_ICON_STEREOTYPE_PRESENTATION)) ) {
			this.setIcon(icon);
			if (iconLabel == null) {
				createIconLabel();
			}
			iconLabel.setIcon(icon);
			iconLabel.repaint();
			this.add(iconLabel,0);
			this.repaint();		
		}
		else if (presentation.equals(ModelerHelper.DEFAULT_PRESENTATION) 
				|| presentation.equals(ModelerHelper.TEXT_STEREOTYPE_PRESENTATION)) {
			setIcon(PapyrusPlugin.getImage(PapyrusPlugin.UML_ICONS_16x16+"Component.gif"));
		}
		else {
			if (iconLabel != null) {
				iconLabel.setIcon(null);
				iconLabel.repaint();
				if (iconLabel.getParent() != null)	{
					this.remove(iconLabel);
				}
				this.repaint();
			}
		}
		return;
	}
	

}

